#include<windows.h>
#include "resource.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/timeb.h>
#include<conio.h>
#define h 150
#define w 150
double PCFreq = 0.0;
__int64 CounterStart = 0;



void StartCounter()
{
    LARGE_INTEGER li;
    if(!QueryPerformanceFrequency(&li))
		printf("QuerryPerformance Failrd");
    PCFreq = double(li.QuadPart)/1000000000.0;

    QueryPerformanceCounter(&li);
    CounterStart = li.QuadPart;
}
double GetCounter()
{
    LARGE_INTEGER li;
    QueryPerformanceCounter(&li);
    return double(li.QuadPart-CounterStart)/PCFreq;
}
struct tree//ARBORE AA->
{
	int val;
	int level;
	tree* left,*right,*parent;
}* root;
void SKEW(tree* oldparent,tree* &root)//daca exista o legatura orizontala spre stanga face o rotatie dreapta si actualizeaza nivelurile
{
	tree* nou=oldparent->left;
	if(oldparent->parent->left==oldparent)
		oldparent->parent->left=nou;
	else
		oldparent->parent->right=nou;
	nou->parent=oldparent->parent;
	oldparent->parent=nou;
	oldparent->left=nou->right;
	if(oldparent->left)
		oldparent->left->parent=oldparent;
	nou->right=oldparent;
	if(oldparent->left)
		oldparent->level=oldparent->left->level+1;
	else
		oldparent->level=1;
	if(oldparent==root)
		root=nou;
}
int  SPLIT(tree* oldparent,tree* &root)//daca exista 2 legaturi orizontale spre dreapta face o rotatie stanga si actualizeaza nivelurile
{
	tree* nou=oldparent->right;
	if(nou&&nou->right&&nou->right->level==oldparent->level)
	{
		if(oldparent->parent)
		{
			if(oldparent->parent->left==oldparent)
				oldparent->parent->left=nou;
			else
				oldparent->parent->right=nou;
		}
		else
			root=nou;
		nou->parent=oldparent->parent;
		oldparent->parent=nou;
		oldparent->right=nou->left;
		if(oldparent->right)
			oldparent->right->parent=oldparent;
		nou->left=oldparent;
		nou->level=oldparent->level+1;
		return 1;
	}
	return 0;
}
tree* INSERT(int val,tree* &root)//inserarea unui element in arbore
{
	tree* nou=(tree*)malloc(sizeof(tree));
	nou->right=nou->left=NULL;
	nou->val=val;
	nou->level=1;
	if(root==NULL)
	{
		nou->parent=NULL;
		root=nou;
		return nou;
	}
	tree* p=root;
	while(p)
	{
		if(val<p->val)
		{
			if(p->left==NULL)
			{
				p->left=nou;
				nou->parent=p;
				return nou;
			}
			else
				p=p->left;
		}
		else
		{
			if(p->right==NULL)
			{
				p->right=nou;
				nou->parent=p;
				return nou;
			}
			else
				p=p->right;
		}
	}
}
void rebalanceafteinsertion(tree* neww)//actualizarea arborelui dupa inserarea unui element
{
	tree* nou=neww->parent;
	if(nou==root&&root->left) 
	{
		if(nou->level!= nou->left->level +1)
		{
			tree* man=neww->right;
			neww->right=nou;
			nou->parent=neww;
			neww->parent=neww->left=NULL;
			nou->left=man;
			if(man)
				man->parent=nou;
			root=neww;
			while(neww->right)
				neww=neww->right;

		}
	}
	for(nou=neww->parent;nou!=root&&nou;nou=nou->parent)
	{
		if(nou->level!=(nou->left? nou->left->level +1 :1))
		{
			SKEW(nou,root);
			if(!nou->right ||nou->level!=nou->right->level)
				nou=nou->parent;
		}

		if(!SPLIT(nou->parent,root))
			break;
	}
	if(nou==root&&root->right&&nou->left)
	{
	if(nou->level!= nou->left->level +1)
	{
			neww=nou->left;
			tree* man=neww->right;
			neww->right=nou;
			nou->parent=neww;
			neww->parent=NULL;
			nou->left=man;
			if(man)
				man->parent=nou;
			root=neww;
			nou=root;
			SPLIT(nou,root);
	}
	}
}
tree* SEARCH(int val)
{
	tree* man=root;
	while(man)
	{
		if(val==man->val)
			return man;
		else
		{
			if(val<man->val)
				man=man->left;
			else
				man=man->right;
		}
	}
	return NULL;
}
void DEZALOC(tree* nod)
{
	if(nod==NULL)
		return;
	DEZALOC(nod->left);
	DEZALOC(nod->right);
	free(nod);
}
//<-ARBORE AA

struct treeNode{//ARBORE RN->
	int val;
	treeNode *parent,*left,*right;
	int color;//rosu=0...negru=1
	int bh;//inaltimea neagra
};

treeNode *root_RN;

void insert_case1(treeNode *nod);

treeNode *grandparent(treeNode *nod)
{
	treeNode *p=nod->parent;
	return p->parent;
}
treeNode *uncle(treeNode *nod)
{
	treeNode *g=grandparent(nod);
	if(g==NULL)
		return NULL;
	if(g->left == nod->parent)
		return g->right;
	else
		return g->left;
}
void rotate_right(treeNode *nod)
{

	treeNode *parent=nod->parent,*r=nod->right;
	nod->parent = parent->parent;
	if(nod->parent!=NULL)
	{
		if(nod->parent->left==parent)
			nod->parent->left=nod;
		else
			nod->parent->right=nod;
		nod->right=parent;
		parent->parent=nod;
		parent->left=r;
		if(r!=NULL)
			r->parent=parent;
	}
	else
	{
		if(parent==root_RN)
		{
			root_RN=nod;
			r=root_RN->right;
			root_RN->right=parent;
			parent->parent=root_RN;
			parent->left=r;
			if(r!=NULL)
				r->parent=parent;
		}
	}
}
void rotate_left(treeNode *nod)
{
	treeNode *parent=nod->parent,*l=nod->left;
	nod->parent=parent->parent;
	if(nod->parent!=NULL)
	{
		if(nod->parent->left==parent )
			nod->parent->left=nod;
		else
			nod->parent->right=nod;
	nod->left=parent;
	parent->parent=nod;
	parent->right=l;
	if(l!=NULL)
		l->parent=parent;
	}
	else
	{
		if(parent==root_RN)
		{
			root_RN=nod;
			l=root_RN->left;
			root_RN->left=parent;
			parent->parent=root_RN;
			parent->right=l;
			if(l!=NULL)
				l->parent=parent;
		}
	}
}
void insert_case5(treeNode *nod)

{
	treeNode *g=grandparent(nod);
	nod->parent->color=1;
	if(g)
	g->color=0;
	if(nod==nod->parent->left)
	{
		rotate_right(nod->parent);
	}
	else
		rotate_left(nod->parent);
}

void insert_case4(treeNode *nod)
{
	treeNode *g=grandparent(nod);
	if(g)
	{
		if((nod==nod->parent->right) && (nod->parent == g->left))
		{
			rotate_left(nod);
			nod=nod->left;
		}
		else
			if((nod==nod->parent->left) && (nod->parent == g->right))
			{
				rotate_right(nod);
				nod=nod->right;
			}
	}
	insert_case5(nod);
}

void insert_case3(treeNode *nod)
{
	treeNode *u=uncle(nod),*g;
	if((u!=NULL) && (u->color==0))
	{
		nod->parent->color=1;
		u->color=1;
		g=grandparent(nod);
		g->color=0;
		insert_case1(g);
	}
	else
		insert_case4(nod);
}

void insert_case2(treeNode *nod)
{
	if(nod->parent->color==1)
		return;
	else
		insert_case3(nod);
}

void insert_case1(treeNode *nod)
{
	if(nod->parent==NULL)
		nod->color=1;
	else
		insert_case2(nod);
}

void insert_RN(int val)
{
	treeNode *nod=(treeNode *)malloc(sizeof(treeNode));
	nod->val=val;
	nod->color=0;
	nod->bh=0;
	nod->left=nod->right=nod->parent=NULL;
	if(root_RN==NULL)
	{
		insert_case1(nod);
		root_RN=nod;
		return;
	}
	treeNode *p=root_RN;
	while(p!=NULL)
	{
		if(val<p->val)
			if(p->left==NULL)
			{
				p->left=nod;
				nod->parent=p;
				insert_case1(nod);
				return;
			}
			else
				p=p->left;
		else
			if(p->right==NULL)
			{
				p->right=nod;
				nod->parent=p;
				insert_case1(nod);
				return;
			}
			else
				p=p->right;
	}
}

treeNode *search_RN(int val)
{
	treeNode *p=root_RN;
	while(p)
	{
		if(val==p->val)
			return p;
		else
		{
		if(val<p->val)
			p=p->left;
		else
			p=p->right;
		}
	}
	return NULL;
}
void dezaloc_RN(treeNode *nod)
{
	if(nod==NULL)
		return;
	dezaloc_RN(nod->left);
	dezaloc_RN(nod->right);
	free(nod);
}
//<-ARBORE RN


struct avl_node {
    int data;
    struct avl_node *left;
    struct avl_node *right;
}*roottt;

int find_height(struct avl_node *node)
{
    int height=0;
    if (node !=NULL){
        int left_height= find_height(node ->left);
        int right_height= find_height(node -> right);
        int max=(left_height > right_height) ? left_height : right_height;
        height = 1+ max;
    }
    return height;
}

int get_diff(struct avl_node *node)
{
    int left_height=find_height(node -> left);
    int right_height=find_height(node -> right);
    int b_factor= left_height - right_height;
    return b_factor;
}  
 avl_node* right_right_rotation(struct avl_node *parent)
{
    struct avl_node *node1;
    node1=parent ->right;
    parent->right = node1 -> left;
    node1 -> left= parent;
    return node1;
}
 avl_node* left_left_rotation(struct avl_node *parent)
{
    struct avl_node *node1;
    node1 = parent -> left;
    parent -> left = node1 -> right;
    node1 -> right = parent;
    return node1;
}
 avl_node* right_left_rotation(struct avl_node *parent)
{
    struct avl_node *node1;
    node1=parent -> right;
    parent->right = left_left_rotation(node1);
    return right_right_rotation(parent);
}
 avl_node* left_right_rotation(struct avl_node *parent)
{
    struct avl_node *node1;
    node1= parent -> left;
    parent-> left = right_right_rotation(node1);
    return left_left_rotation(parent);
}
 avl_node* balancing(struct avl_node *node)
{
    int b_f= get_diff(node);
    if (b_f >1) {
        if (get_diff(node->left) >0)
            node=left_left_rotation(node);
        else
            node=left_right_rotation(node);
    }
    else if(b_f < -1) {
        if(get_diff(node ->right) >0)
            node=right_left_rotation(node);
        else
            node=right_right_rotation(node);
    }
    return node;
}        
 avl_node* insert(struct avl_node *root,int val)
{
    if (root==NULL) {
        root = (struct avl_node*) malloc(sizeof(struct avl_node));
        root -> data = val;
        root -> left = NULL;
        root -> right = NULL;
        return root;
    }
    else if (val < root->data) {
        root->left = insert(root->left, val);
        root=balancing(root);
    }
    else if (val > root->data) {
        root->right = insert(root->right, val);
        root=balancing(root);
    }
    return root;
}
 avl_node* SEARCH_AVL(int val)
 {
	 avl_node* man=roottt;
	 while(man)
	 {
		 if(val==man->data)
			 return man;
		 else
		 {
			 if(val<man->data)
				 man=man->left;
			 else
				 man=man->right;
		 }
	 }
	 return NULL;
 }
 void dezaloc_avl(avl_node* nod)
 {
	 if(nod==NULL)
		 return;
	 dezaloc_avl(nod->left);
	 dezaloc_avl(nod->right);
	 free(nod);
 }



//<< arbore AVL


const char ClassName[]="MyClass";
int i=0,*v,add[1000],index,ifisier;
double taatotal2,taatotal,taatotal3;
HWND Toolbar = NULL;
HWND Toolbar_GENERARE = NULL, Toolbar_TASTATURA = NULL, Toolbar_DESEN = NULL, Toolbar_GRAFIC = NULL, Toolbar_Arbore = NULL,Toolbar_FISIER,Toolbar_Help = NULL;
int verify_int(char*s)
{
	for(int i=0;i<strlen(s);i++)
	{
		if(!isdigit(s[i]))
			return 0;
	}
	return 1;
}
void gen_vec_distinct(int n)
{
	for(int i=0;i<n;i++)
	{
		int g=1,nr;
		while(g==1)
		{
			 nr=rand()*rand();
			g=0;
			for(int j=0;j<i;j++)
			{
				if(nr==v[j])
				{
					g=1;
					break;
				}
			}
		}
		v[i]=nr;
	}
}
int verify_add(int val,int i)
{
	for(int j=0;j<i;j++)
	{
		if(val==v[j])
			return 0;
	}
	return 1;
}
int functie(int val1,int val2,int val3)
{
	int max=val1;
	if(max<val2)
		max=val2;
	if(max<val3)
		max=val3;
	return max;
}
float caut_const(int max)
{
	float c=1;
	while(max>170 || max<50)
	{
		if(max<60)
		{
			max=(float)(max*1.4);
			c=(float)(c*1.4);
		}
		else
		{
			max=(float)(max*0.1);
			c=(float)(c*0.1);
		}
	}
	return c;
}
float caut_const_2(int max)
{
	float c=1;
	while(max>150 || max<50)
	{
		if(max<60)
		{
			max=(float)(max*1.3);
			c=(float)(c*1.3);
		}
		else
		{
			max=(float)(max*0.9);
			c=(float)(c*0.9);
		}
	}
	return c;
}
int verificare_intregi(char* nume)
{
	FILE *f=fopen(nume,"r");
	char c;
	while (fscanf(f,"%c",&c)!=EOF)
	{
		if(isdigit(c)|| c==' '|| c=='\n');
		else
		{
			fclose(f);
			return 0;
		}
	}
	fclose(f);
	return 1;
}
int inserare_fisier( char* nume)
{
	FILE *f=fopen(nume,"r");
	if(f==NULL)
		return 0;
	else
	{
		if(verificare_intregi(nume))
		{
			int b;
			while(fscanf(f,"%d",&b)!=EOF)
			{
				if(verify_add(b,ifisier))
				{
					v=(int*)realloc(v,(ifisier+1)*sizeof(int));
					v[ifisier]=b;
					ifisier++;
				}
			}
		}
	}
	fclose(f);
	return 1;
}
BOOL CALLBACK ToolDlgProc (HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam);

BOOL CALLBACK ToolDlgProc_GENERARE(HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam);

BOOL CALLBACK ToolDlgProc_DESEN(HWND hwnd , UINT Msg, WPARAM wParam, LPARAM lParam);

struct cerc
{
	int x,y,index;
	int value;
	int level;
	bool exista;
};
cerc n[10];

BOOL CALLBACK ToolDlgProc_FISIER(HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam)
{
	switch(Msg)
	{
	case WM_COMMAND:
		{
			switch(LOWORD (wParam))
			{
				case IDC_BUTTON2:
					{
			
							MessageBox(hwnd,"You chose to return","This is a message:",MB_OK | MB_ICONEXCLAMATION);
							SendMessage( Toolbar ,129,NULL,NULL);
							SendMessage( Toolbar ,122,NULL,NULL);
							EndDialog(hwnd,IDC_BUTTON2);
							free(v);
							v=NULL;
							ifisier=0;
							index=0;
							tree* nou=root;
							treeNode *nou_RN=root_RN;
							avl_node* nou_avl=roottt;
							DEZALOC(nou);
							dezaloc_RN(nou_RN);
							dezaloc_avl(nou_avl);
							root=NULL;
							root_RN=NULL;
							roottt=NULL;
					}
					break;
				case IDC_BUTTON3:
					{
						int wmId, wmEvent,i=0;
						PAINTSTRUCT ps;
						HDC hdc,hdc2;
						LPCSTR Y;
						HICON hicon, hicon_sm;
						HWND d1=NULL, d2=NULL, d3=NULL;
   					  HDC hDC;
						OPENFILENAME fon;
						char szFileName[MAX_PATH] = "";
						HPEN bluePen; 
						HGDIOBJ oldPen;
						HFONT font;
						hdc=GetDC(hwnd);
						ZeroMemory(&fon,sizeof(fon));
						fon.lStructSize = sizeof(fon);
						fon.hwndOwner = hwnd;
						fon.lpstrFilter =TEXT("Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0");
						fon.lpstrFile =szFileName;
						fon.nMaxFile = MAX_PATH;
						fon.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
						fon.lpstrDefExt =TEXT("txt");
						if(GetOpenFileName(&fon))
						{
							i=inserare_fisier(szFileName);
							if (i==1)
							{
								if(ifisier!=0)
								{
									index=ifisier;
									EnableWindow(GetDlgItem( hwnd,IDC_BUTTON3), FALSE);
									 SendMessage(Toolbar,113,NULL,NULL);
									  SendMessage(Toolbar_DESEN,99,NULL,NULL);
									 for(int i=0;i<ifisier;i++)
									 {
										 tree* nod=INSERT(v[i],root);
										 rebalanceafteinsertion(nod);
										 insert_RN(v[i]);
										 roottt=insert(roottt,v[i]);
									 }
									 SendMessage(Toolbar_DESEN,100,NULL,NULL);
									 MessageBox(hwnd,"The elements were inserted","Attention",MB_OK|MB_ICONEXCLAMATION);
								}
								else
									MessageBox(NULL,"The file is empty orit doesnt contain ONLY integer positive values","New File", MB_OK | MB_ICONINFORMATION);
							}
							else
								MessageBox(hwnd,"A FOST O PROBLEMA LA DESCHIDEREA FISIERULUI","Eroare",MB_OK);
						}
					}
					break;
				default:
					break;
			}
		}
		break;
	default:
		return ToolDlgProc ( hwnd,  Msg, wParam, lParam);
	}
	return TRUE;
}

BOOL CALLBACK ToolDlgProc_Arbore(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	tree *p=root ,*q=NULL;
	for(int j=0;j<=14;j++)
		n[j].exista=false;
	n[0].x=680;
	n[0].y=50;
	n[1].x=n[0].x-300;
	n[1].y=n[0].y+h;
	n[2].x=n[0].x+300;
	n[2].y=n[0].y+h;
	n[2].index=n[1].index=0;
	n[3].x=n[1].x-w;
	n[3].y=n[1].y+h;
	n[4].x=n[1].x+w;
	n[4].y=n[1].y+h;
	n[4].index=n[3].index=1;
	n[5].x=n[2].x-w;
	n[5].y=n[2].y+h;
	n[6].x=n[2].x+w;
	n[6].y=n[2].y+h;
	n[5].index=n[6].index=2;
	n[7].x=n[3].x-100;
	n[7].y=n[3].y+h;
	n[8].x=n[3].x+100;
	n[8].y=n[3].y+h;
	n[7].index=n[8].index=3;
	n[9].x=n[4].x-100;
	n[9].y=n[4].y+h;
	n[10].x=n[4].x+100;
	n[10].y=n[4].y+h;
	n[9].index=n[10].index=4;
	n[11].x=n[5].x-100;
	n[11].y=n[5].y+h;
	n[12].x=n[5].x+100;
	n[12].y=n[5].y+h;
	n[12].index=n[11].index=5;
	n[13].x=n[6].x-100;
	n[13].y=n[6].y+h;
	n[14].x=n[6].x+100;
	n[14].y=n[6].y+h;
	n[13].index=n[14].index=6;
	if(p)
	{
		n[0].level=p->level;
		n[0].exista=true;
		n[0].value=p->val;
	}
	p=p->left;
	if(p)
		q=p->right;
	if(p)
	{
		n[1].level=p->level;
		n[1].exista=true;
		n[1].value=p->val;
		p=p->left;
		if(p)
		{
			n[3].level=p->level;
			n[3].exista=true;
			n[3].value=p->val;
			if(p->left){
				n[7].level=p->left->level;
				n[7].exista=true;
				n[7].value=p->left->val;}
			if(p->right){
				n[8].level=p->right->level;
				n[8].exista=true;
				n[8].value=p->right->val;}
		}
	}
	if(q)
	{
		n[4].level=q->level;
		n[4].exista=true;
		n[4].value=q->val;
		if(q->right){
			n[10].level=q->right->level;
			n[10].exista=true;
			n[10].value=q->right->val;}
		if(q->left){
			n[9].level=q->left->level;
			n[9].exista=true;
			n[9].value=q->left->val;}
	}
	p=root->right;
	if(p)
	{
		n[2].level=p->level;
		n[2].exista=true;
		n[2].value=p->val;
		q=p->right;//6
		p=p->left;//5
		if(p)
		{
			n[5].level=p->level;
			n[5].exista=true;
			n[5].value=p->val;
			if(p->left){
				n[11].level=p->left->level;
				n[11].exista=true;
				n[11].value=p->left->val;}
			if(p->right){
				n[12].level=p->right->level;
				n[12].exista=true;
				n[12].value=p->right->val;}
		}
		if(q)
		{
			n[6].level=q->level;
			n[6].exista=true;
			n[6].value=q->val;
			if(q->left){
				n[13].level=q->left->level;
				n[13].exista=true;
				n[13].value=q->left->val;}
			if(q->right){
				n[14].level=q->right->level;
				n[14].exista=true;
				n[14].value=q->right->val;}
		}
	}
	switch(Msg)
	{
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd,&ps);
			HPEN hPen,h2;
			COLORREF qLineColor,q;
			q=RGB(0,0,255);
			qLineColor = RGB(255,25,5);
			hPen = CreatePen(PS_SOLID,4,qLineColor);
			h2=CreatePen(PS_SOLID,4,q);
			SelectObject(hdc,hPen);
			Rectangle(hdc,1,2,1306,639);
			hPen = CreatePen(PS_SOLID,3,qLineColor);
			Ellipse(hdc,n[0].x,n[0].y,n[0].x+50,n[0].y+50);
			char s[10];
			char ss[50],sss[100];
			int k=0;
			TextOut(hdc,n[0].x+21,n[0].y+19,"1",1);
			TextOut(hdc,n[0].x+51,n[0].y+19,"L:",2);
			itoa(root->level,sss,10);
			TextOut(hdc,n[0].x+61,n[0].y+19,sss,strlen(sss));
			for(int j=1;j<=14;j++)
			{
				if(n[j].exista)
				{
					k++;
					Ellipse(hdc,n[j].x,n[j].y,n[j].x+50,n[j].y+50);
					MoveToEx(hdc,n[n[j].index].x+25,n[n[j].index].y+50,NULL);
					LineTo(hdc,n[j].x+25,n[j].y);
					itoa(k+1,s,10);
					itoa(n[j].level,sss,10);
					if(j<9)
					{
						TextOut(hdc,n[j].x+21,n[j].y+19,s,strlen(s));
						TextOut(hdc,n[j].x+51,n[j].y+19,"L:",2);
						TextOut(hdc,n[j].x+61,n[j].y+19,sss,strlen(sss));
					}
					else
					{
						TextOut(hdc,n[j].x+18,n[j].y+19,s,strlen(s));
						TextOut(hdc,n[j].x+50,n[j].y+19,"L:",2);
						TextOut(hdc,n[j].x+60,n[j].y+19,sss,strlen(sss));

					}
				}
			}
			Rectangle(hdc,5,10,225,(k+2)*25+10);
			int m=35;
			for(int j=0;j<=k;j++)
			{
				MoveToEx(hdc,5,m,NULL);
				LineTo(hdc,224,m);
				m=m+25;
			}
			MoveToEx(hdc,110,10,NULL);
			LineTo(hdc,110,m-1);
			TextOut(hdc,11,15,"NODE nr",7);
			TextOut(hdc,115,15,"NODE value",10);
			m=40;
			int x=0,y=0,val;
			for(int j=0;j<=k;j++)
			{
				itoa(j+1,s,10);
				TextOut(hdc,11,m,s,strlen(s));
				x=y=val=0;
				while(x<j+1)
				{
					if(n[y].exista)
					{
						x++;
						val=n[y].value;
					}
					y++;
				}
				itoa(val,ss,10);
				TextOut(hdc,115,m,ss,strlen(ss));
				m=m+25;
			}
			SelectObject(hdc,h2);
			Rectangle(hdc,290,10,380,48);
			TextOut(hdc,300,20,"L : LEVEL",9);
			EndPaint(hwnd,&ps);
		}
		break;
	case WM_CLOSE:
		{
		EndDialog(hwnd,WM_CLOSE);
		DestroyWindow(hwnd);
		}
		break;
	default:
		return FALSE;
	}
	return TRUE;
}

int yy=0,yyy=0;

BOOL CALLBACK ToolDlgProc_GRAFIC(HWND hwnd, UINT Msg, WPARAM wParam ,LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	switch(Msg)
	{
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd,&ps);
			HPEN hPen;
			COLORREF qLineColor;
			qLineColor = RGB(255,25,5);
			hPen = CreatePen(PS_SOLID,4,qLineColor);
			SelectObject(hdc,hPen);
			Rectangle(hdc,1,2,408,271);

			HPEN hPen1;
			hPen1 = CreatePen(PS_SOLID,3,qLineColor);
			SelectObject(hdc,hPen1);
			MoveToEx(hdc,60,40,NULL);
			LineTo(hdc,60,230);
			MoveToEx(hdc,60,30,NULL);
			LineTo(hdc,65,40);
			MoveToEx(hdc,60,30,NULL);
			LineTo(hdc,55,40);
			MoveToEx(hdc,60,230,NULL);
			LineTo(hdc,290,230);
			MoveToEx(hdc,300,230,NULL);
			LineTo(hdc,290,235);
			MoveToEx(hdc,300,230,NULL);
			LineTo(hdc,290,225);
			TextOut(hdc,292,10," AA Tree time",14);
			TextOut(hdc,292,30," RB Tree time",14);
			TextOut(hdc,292,50," AVL Tree time",15);
			HBRUSH hBrush ;
			qLineColor = NULL;
			hPen1 = CreatePen(PS_SOLID,2,qLineColor);
			SelectObject(hdc,hPen1);
			hBrush = CreateSolidBrush(RGB(200,0,0));
			SelectObject(hdc,hBrush);
			Rectangle(hdc,265,15,285,25);
			hBrush = CreateSolidBrush(RGB(0,200,0));
			SelectObject(hdc,hBrush);
			Rectangle(hdc,265,35,285,45);
			hBrush = CreateSolidBrush(RGB(0,0,200));
			SelectObject(hdc,hBrush);
			Rectangle(hdc,265,55,285,65);
		//	taatotal2,taatotal,taatotal3;
			int max=functie((int)taatotal,(int)taatotal2,(int)taatotal3);
			if(max<180 && max>17)
			{
				int j;
				float c=caut_const(max);
				char s[20];
				hBrush = CreateSolidBrush(RGB(200,0,0));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,63,229,130,229-taatotal*c);
				else
					for(j=1;j<=taatotal*c;j++)
					{
						Sleep(12);
						Rectangle(hdc,63,229,130,229-j);
					}
				itoa(taatotal,s,10);
				TextOut(hdc,63,235-taatotal*c,s,strlen(s));
				hBrush = CreateSolidBrush(RGB(0,200,0));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,131,229,200,229-taatotal2*c);
				else
					for(j=1;j<=taatotal2*c;j++)
					{
						Sleep(12);
						Rectangle(hdc,131,229,200,229-j);
					}
				itoa(taatotal2,s,10);
				TextOut(hdc,133,235-taatotal2*c,s,strlen(s));
				hBrush = CreateSolidBrush(RGB(0,0,200));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,201,229,270,229-taatotal3*c);
				else
				{
					for(j=1;j<=taatotal3*c;j++)
					{
						Sleep(12);
						Rectangle(hdc,201,229,270,229-j);
					}
					yy=1;
				}
				itoa(taatotal3,s,10);
				TextOut(hdc,203,235-taatotal3*c,s,strlen(s));
			}
			if(max<17)
			{
				char s[20];
				int j;
				hBrush = CreateSolidBrush(RGB(200,0,0));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,63,229,130,229-taatotal*10);
				else
					for(j=1;j<=taatotal*10;j++)
					{
						Sleep(12);
						Rectangle(hdc,63,229,130,229-j);
					}
				itoa(taatotal,s,10);
				TextOut(hdc,65,235-taatotal*10,s,strlen(s));
				hBrush = CreateSolidBrush(RGB(0,200,0));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,131,229,200,229-taatotal2*10);
				else
					for(j=1;j<=taatotal2*10;j++)
					{
						Sleep(12);
						Rectangle(hdc,131,229,200,229-j);
					}
				itoa(taatotal2,s,10);
				TextOut(hdc,133,235-taatotal2*10,s,strlen(s));
				hBrush = CreateSolidBrush(RGB(0,0,200));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,201,229,270,229-taatotal3*10);
				else
				{
					for(j=1;j<=taatotal3*10;j++)
					{
						Sleep(12);
						Rectangle(hdc,201,229,270,229-j);
					}
					yy=1;
				}
				itoa(taatotal3,s,10);
				TextOut(hdc,203,235-taatotal3*10,s,strlen(s));
				
			}
			if(max>180)
			{
				char s[20];
				int j;
				float c=caut_const_2(max);
				hBrush = CreateSolidBrush(RGB(200,0,0));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,63,229,130,229-taatotal*c);
				else
					for(j=1;j<=taatotal*c;j=j+1)
					{
						Sleep(12);
						Rectangle(hdc,63,229,130,229-j);
					}
				itoa(taatotal,s,10);
				TextOut(hdc,65,235-taatotal*c,s,strlen(s));
				hBrush = CreateSolidBrush(RGB(0,200,0));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,131,229,200,229-taatotal2*c);
				else
					for(j=1;j<=taatotal2*c;j=j+1)
					{
						Sleep(12);
						Rectangle(hdc,131,229,200,229-j);
					}
				itoa(taatotal2,s,10);
				TextOut(hdc,133,235-taatotal2*c,s,strlen(s));
				hBrush = CreateSolidBrush(RGB(0,0,200));
				SelectObject(hdc,hBrush);
				if(yy)
					Rectangle(hdc,201,229,270,229-taatotal3*c);
				else
				{
					for(j=1;j<=taatotal3*c;j=j+1)
					{
						Sleep(12);
						Rectangle(hdc,201,229,270,229-j);
					}
					yy=1;
				}
				itoa(taatotal3,s,10);
				TextOut(hdc,203,235-taatotal3*c,s,strlen(s));
			}
			EndPaint(hwnd,&ps);
		}
		break;
	default:
		return ToolDlgProc ( hwnd,  Msg, wParam, lParam);
	}
	return TRUE;
}


BOOL CALLBACK ToolDlgProc_DESEN(HWND hwnd , UINT Msg, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	switch(Msg)
	{
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd,&ps);
			HPEN hPen;
			COLORREF qLineColor;
			qLineColor = RGB(255,25,5);
			hPen = CreatePen(PS_SOLID,2,qLineColor);
			SelectObject(hdc,hPen);
			Rectangle(hdc,380,5,1350,384);
			Rectangle(hdc,385,10,1345,379);
			HPEN hLinePen;
			hLinePen = CreatePen(PS_SOLID,2,qLineColor);
			SelectObject(hdc,hLinePen);
			MoveToEx(hdc,10,10,NULL);
			LineTo(hdc,380,10);
			MoveToEx(hdc,5,5,NULL);
			LineTo(hdc,382,5);
			MoveToEx(hdc,10,377,NULL);
			LineTo(hdc,380,377);
			MoveToEx(hdc,5,383,NULL);
			LineTo(hdc,385,383);
			MoveToEx(hdc,5,4,NULL);
			LineTo(hdc,5,383);
			MoveToEx(hdc,10,9,NULL);
			LineTo(hdc,10,377);
			MoveToEx(hdc,870,9,NULL);
			LineTo(hdc,870,377);
			MoveToEx(hdc,385,65,NULL);
			LineTo(hdc,1344,65);
			EndPaint(hwnd,&ps);
		}
	case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
			case IDC_CAUT:
				{
					char s[50];
					int n;
					GetDlgItemText(hwnd,IDC_EDIT1,s,48);
					if(!verify_int(s)|| strcmp(s,"")==0)
						MessageBox(hwnd,"Introduce a integer positive value","Error",MB_OK|MB_ICONEXCLAMATION);
					else
					{
						 n=GetDlgItemInt(hwnd,IDC_EDIT1,NULL,TRUE);
						StartCounter();
						tree* nou=SEARCH(n);
						taatotal=GetCounter();
						StartCounter();
						treeNode *nou_RN=search_RN(n);
						taatotal2=GetCounter();
						StartCounter();
						avl_node* nou_avl=SEARCH_AVL(n);
						taatotal3=GetCounter();
						if(!nou_RN||!nou||!nou_avl)
							MessageBox(hwnd,"The searched element doesn t exist","Attention",MB_OK|MB_ICONEXCLAMATION);
						else
						{
							char s[50];
							itoa(taatotal,s,10);
							MessageBox(hwnd,s," AA tree",MB_OK);
							itoa(taatotal2,s,10);
							MessageBox(hwnd,s," RB tree",MB_OK);
							itoa(taatotal3,s,10);
							MessageBox(hwnd,s," AVL tree",MB_OK);
							/////////////////////////////
							Toolbar_GRAFIC = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_SMALL3),
										hwnd,ToolDlgProc_GRAFIC);
							if(Toolbar_GRAFIC != NULL)
							{
								yy=0;
								ShowWindow(Toolbar_GRAFIC, SW_SHOW);
							}
							else
							MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",	
									MB_OK | MB_ICONINFORMATION);
							//////////////////////////
						}
						///Cronometrarea cautarii unui element in cei 3 arbori
					}
					SetWindowText( GetDlgItem( hwnd, IDC_EDIT1 ), "" );
					
				}
				break;
			case IDC_TMEDIU:
				{
					StartCounter();
					for(int i=0;i<index;i++)
						treeNode *nou_RN=search_RN(v[i]);
					taatotal2=GetCounter();
					StartCounter();
					for(int i=0;i<index;i++)
						tree* nou=SEARCH(v[i]);
					taatotal=GetCounter();
					StartCounter();
					for(int i=0;i<index;i++)
					{
						avl_node* nou_avl=SEARCH_AVL(v[i]);
						if(!nou_avl)
							MessageBox(hwnd,"Nu s a gasit","eroare",MB_OK);
					}
					taatotal3=GetCounter();
					/*
					char s[100];
					itoa(taatotal,s,10);
					MessageBox(hwnd,s,"Arbore AA",MB_OK|MB_ICONEXCLAMATION);
					itoa(taatotal2,s,10);
					MessageBox(hwnd,s,"Arbore RN",MB_OK | MB_ICONEXCLAMATION);
					itoa(taatotal3,s,10);
					MessageBox(hwnd,s,"ARBORE AVL",MB_OK|MB_ICONEXCLAMATION);
					*/
					///////////////
					Toolbar_GRAFIC = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_SMALL2),
					hwnd,ToolDlgProc_GRAFIC);
					if(Toolbar_GRAFIC != NULL)
					{
						yy=0;
						ShowWindow(Toolbar_GRAFIC, SW_SHOW);
					}
					else
						MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",	
								MB_OK | MB_ICONINFORMATION);
					//////////////
				}
				break;
			}
		}
		break;
	case 99:
		{
			EnableWindow(GetDlgItem( hwnd,IDC_TMEDIU), FALSE);
			EnableWindow(GetDlgItem(hwnd,IDC_CAUT),FALSE);
		}
		break;
	case 100:
		{	
		     EnableWindow(GetDlgItem( hwnd,IDC_TMEDIU), TRUE);
			 EnableWindow(GetDlgItem(hwnd,IDC_CAUT),TRUE);
		}
		break;
	default :
		return ToolDlgProc ( hwnd,  Msg, wParam, lParam);
	}
	return TRUE;
}


BOOL CALLBACK ToolDlgProc_TASTATURA(HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam)
{
	switch(Msg)
	{
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDC_BUTTON1:
			{
				int n;
				char s[50];
				GetDlgItemText(hwnd,IDC_EDIT1,s,48);
				if(!verify_int(s)||strcmp(s,"")==0)
					MessageBox(hwnd,"Introduce integer positive value","Error",MB_OK|MB_ICONEXCLAMATION);
				else
				{
					n=GetDlgItemInt(hwnd,IDC_EDIT1,NULL,TRUE);
					if(!verify_add(n,index))
						MessageBox(hwnd,"The element exists already .Insert another value","Error",MB_OK|MB_ICONEXCLAMATION);
					else
					{
						v=(int *)realloc(v,(index+1)*sizeof(int));
						v[index]=n;
						tree* nod=INSERT(n,root);
						rebalanceafteinsertion(nod);
						insert_RN(n);
						roottt=insert(roottt,n);
						index++;
						MessageBox(hwnd,"Succesfully inserted element","Information",MB_OK);
					}
				}
				SetWindowText( GetDlgItem( hwnd, IDC_EDIT1 ), "" );
			}
			break;
		case IDC_BUTTON2:
			{
				EnableWindow(GetDlgItem( hwnd,IDC_BUTTON2), FALSE);
				EnableWindow(GetDlgItem(hwnd,IDC_BUTTON1),FALSE);
				SendMessage(Toolbar_DESEN,100,NULL,NULL);
				SendMessage(Toolbar,113,NULL,NULL);
				MessageBox(hwnd,"The elements were inserted succesfully","Attention",MB_OK|MB_ICONEXCLAMATION);
				///////////////////////////////
				Toolbar_GRAFIC = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_SMALL2),
					hwnd,ToolDlgProc_GRAFIC);
					if(Toolbar_GRAFIC != NULL)
						ShowWindow(Toolbar_GRAFIC, SW_SHOW);
					else
						MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",	
								MB_OK | MB_ICONINFORMATION);
					////////////////////////
			}
			break;
		case IDC_BUTTON3:
			{
				MessageBox(hwnd,"You chose to return","This is a message:",MB_OK | MB_ICONEXCLAMATION);
				SendMessage( Toolbar ,123,NULL,NULL);
				EndDialog(hwnd,IDC_BUTTON2);
				index=0;
				treeNode *nou_RN=root_RN;
				tree *nou=root;
				avl_node* nou_avl=roottt;
				dezaloc_RN(nou_RN);
				root_RN=NULL;
				DEZALOC(nou);
				dezaloc_avl(nou_avl);
				root=NULL;
				roottt=NULL;
				free(v);
				v=NULL;
			}
		}
		break;
	default:
		return ToolDlgProc ( hwnd,  Msg, wParam, lParam);
	}
	return TRUE;
}


BOOL CALLBACK ToolDlgProc_GENERARE(HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam)
{
	switch(Msg)
	{
	case WM_COMMAND:
		switch(LOWORD (wParam))
		{
			case IDC_BUTTON1:
				{
					char s[50];
					int n;
					GetDlgItemText(hwnd,IDC_EDIT1,s,48);
					if(!verify_int(s)|| strcmp(s,"")==0)
						MessageBox(hwnd,"Introduce integer positive numbers","Error",MB_OK|MB_ICONEXCLAMATION);
					else
					{
						 n=GetDlgItemInt(hwnd,IDC_EDIT1,NULL,TRUE);
						 index=n;
						 EnableWindow(GetDlgItem( hwnd,IDC_BUTTON1), FALSE);
						 SendMessage(Toolbar,113,NULL,NULL);
						 SendMessage(Toolbar_DESEN,99,NULL,NULL);
						 v=(int*)malloc(n*sizeof(int));
						 gen_vec_distinct(n);
						 char s[100];
						itoa(v[index-1],s,10);
						 for(int i=0;i<n;i++)
						 {
							 tree* nod=INSERT(v[i],root);
							 rebalanceafteinsertion(nod);
							 insert_RN(v[i]);
							 roottt=insert(roottt,v[i]);
						 }
						 SendMessage(Toolbar_DESEN,100,NULL,NULL);
						 MessageBox(hwnd,"The tree was built succesfully","Attention",MB_OK|MB_ICONEXCLAMATION);
					}
					SetWindowText( GetDlgItem( hwnd, IDC_EDIT1 ), "" );
				}
			break;
			case IDC_BUTTON2:
				{
					MessageBox(hwnd,"You chose to return","Message",MB_OK | MB_ICONEXCLAMATION);
					SendMessage( Toolbar ,122,NULL,NULL);
					EndDialog(hwnd,IDC_BUTTON2);
					free(v);
					v=NULL;
					index=0;
					tree* nou=root;
					treeNode *nou_RN=root_RN;
					avl_node* nou_avl=roottt;
					DEZALOC(nou);
					dezaloc_RN(nou_RN);
					dezaloc_avl(nou_avl);
					root=NULL;
					root_RN=NULL;
					roottt=NULL;
				}
			break;
		}
		break;
	default:
		return ToolDlgProc ( hwnd,  Msg, wParam, lParam);
	}
	return TRUE;
}

BOOL CALLBACK ToolDlgProc (HWND hwnd, UINT Msg,WPARAM wParam,LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	switch(Msg)
	{
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case IDC_RADIO1:
			{
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO3), FALSE);
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO1), FALSE);
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO4), FALSE);
				MessageBox(hwnd,"You chose to generate a random tree","Information",MB_OK | MB_ICONINFORMATION);
				Toolbar_GENERARE = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_LARGE),
					hwnd,ToolDlgProc_GENERARE);
				if(Toolbar_GENERARE != NULL)
					ShowWindow(Toolbar_GENERARE, SW_SHOW);
				else
					MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",	
							MB_OK | MB_ICONINFORMATION);
			}
			break;
		case IDC_RADIO3:
			{
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO1), FALSE);
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO3), FALSE);
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO4), FALSE);
				MessageBox(hwnd,"You chose to take values from keyboard","Information...",MB_OK | MB_ICONINFORMATION);
				Toolbar_TASTATURA = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_SMALL1),
					hwnd,ToolDlgProc_TASTATURA);
				if(Toolbar_TASTATURA != NULL)
					ShowWindow(Toolbar_TASTATURA, SW_SHOW);
				else
					MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",
							MB_OK | MB_ICONINFORMATION);
			}
			break;
			case IDC_RADIO4:
			{
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO3), FALSE);
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO1), FALSE);
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO4), FALSE);
				Toolbar_FISIER=CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_LARGE2),
					hwnd,ToolDlgProc_FISIER);
				if(Toolbar_FISIER!=NULL)
				{
					
				MessageBox(hwnd,"You chose to take values from file","Message",MB_OK);
					ShowWindow(Toolbar_FISIER,SW_SHOW);
				}
				else
					MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",
							MB_OK | MB_ICONINFORMATION);
			}
			break;
		}
		break;
		case 122:
		{
			EnableWindow( GetDlgItem( hwnd,IDC_RADIO3), TRUE);
			EnableWindow( GetDlgItem( hwnd,IDC_RADIO1), TRUE);
			EnableWindow( GetDlgItem( hwnd,IDC_RADIO4), TRUE);
			EndDialog(Toolbar_DESEN,NULL);
		}
		break;
		case 123:
		 {
			 EnableWindow( GetDlgItem( hwnd,IDC_RADIO1), TRUE);
			 EnableWindow( GetDlgItem( hwnd,IDC_RADIO3), TRUE);
			 EnableWindow( GetDlgItem( hwnd,IDC_RADIO4), TRUE);
			 EndDialog(Toolbar_DESEN,NULL);
		 }
		 break;
		 case 129:
			{
				EnableWindow( GetDlgItem( hwnd,IDC_RADIO1), TRUE);
			 EnableWindow( GetDlgItem( hwnd,IDC_RADIO3), TRUE);
			 EnableWindow( GetDlgItem( hwnd,IDC_RADIO4), TRUE);
			 EndDialog(Toolbar_FISIER,NULL);
			}
			break;
		case 113:
				{
					Toolbar_DESEN = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_LARGE1),
					hwnd,ToolDlgProc_DESEN);
				if(Toolbar_DESEN != NULL)
					ShowWindow(Toolbar_DESEN, SW_SHOW);
				else
					MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",
							MB_OK | MB_ICONINFORMATION);
				}
				break;
	default:
		return DefWindowProc(hwnd,Msg,wParam,lParam);
	}
	return TRUE;
}

BOOL CALLBACK ToolDlgProc_Help(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
	switch(Msg)
	{
	case WM_COMMAND:
			switch(LOWORD(wParam))
			{
			case IDC_BUTTON1:
				EndDialog(Toolbar_Help,IDC_BUTTON1);
			break;
			}
		break;
	case WM_CLOSE:
		EndDialog(Toolbar_Help,WM_CLOSE);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return FALSE;
	}
	return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT Msg, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	PAINTSTRUCT ps;
	switch(Msg)
	{
	case WM_PAINT:
		{
			hdc = BeginPaint(hwnd,&ps);
			HPEN hPen;
			COLORREF qLineColor;
			HFONT hfont;
			qLineColor = RGB(255,25,5);
			hPen = CreatePen(PS_SOLID,4,qLineColor);
			SelectObject(hdc,hPen);
			HBRUSH hbrush = CreateSolidBrush(RGB(0,200,150));
			SelectObject(hdc,hbrush);
			Rectangle(hdc,95,30,1285,150);
			hbrush = CreateSolidBrush(RGB(10,200,10));
			SelectObject(hdc,hbrush);
			Rectangle(hdc,440,250,850,480);
			SetBkMode(hdc,RGB(10,200,10));
			TextOut(hdc,585,252,"Despre aplicatie...",19);
			TextOut(hdc,450,280,"Aplicatia a fost creata si gandita pentru a va",46);
			TextOut(hdc,450,300,"oferi un evaluator grafic privind Arborii AA (Arne Anderson)",60);
			TextOut(hdc,450,320,"ce afiseaza timpii de cautare ai unor valori",44);
			TextOut(hdc,450,340,"fie generate aleatoriu, fie citite din fisier",45);
			TextOut(hdc,450,360,"fie inserate de catre dumneavostra...",37);
			TextOut(hdc,450,380,"Aplicatia va da posibilitatea de a compara acesti timpi",55);
			TextOut(hdc,450,400,"cu cei ai arborilor RN si AVL.",30);
			TextOut(hdc,450,420,"Este foarte usor de folosit si speram ca nu va va dezamagi",60);
			TextOut(hdc,450,440,"alegerea facuta...MULTUMIM!...",30);
			hfont = CreateFont(80, 0, 0, 0, FW_BOLD, 0, 0, 0, ANSI_CHARSET, 
	  OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 
	  FF_MODERN, TEXT("Times New Roman"));
			SelectObject(hdc,hfont);
			TextOut(hdc,165,50,"   Graphic evaluator of AA Trees",32);

			EndPaint(hwnd,&ps);
		}
		break;
	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		case ID_FILE_EXIT40008:
			{
				MessageBox(hwnd,"You chose to exit the application","EXIT",MB_OK);
				PostMessage(hwnd,WM_CLOSE,0,0);
			}
			break;
		case ID_BEGINPROJECT:
			{
				MessageBox(hwnd,"Now choose your option","Information",MB_OK | MB_ICONINFORMATION);
				Toolbar = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_OLE_PROPPAGE_SMALL),
					hwnd,ToolDlgProc);
				if(Toolbar != NULL)
					ShowWindow(Toolbar, SW_SHOW);
				else
					MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",	
						MB_OK | MB_ICONINFORMATION);
				EnableMenuItem(GetMenu(hwnd),ID_BEGINPROJECT,MF_DISABLED);
			}
			break;
			case ID_TREEDRAWING:
			{
				if(root==NULL)
						MessageBox(hwnd,"The tree doesn't contain any element","Attention",MB_OK| MB_ICONEXCLAMATION);
				else
				{
					Toolbar_Arbore = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG1),
						hwnd,ToolDlgProc_Arbore);
					if(Toolbar_Arbore != NULL)
							ShowWindow(Toolbar_Arbore, SW_SHOW);
					else
						MessageBox(hwnd, "Returned NULL", "Warning!",	
							MB_OK | MB_ICONINFORMATION);
				}
			}
			break;
		case ID_HELP40003:
			{
				Toolbar_Help = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DIALOG2),
						hwnd,ToolDlgProc_Help);
					if(Toolbar_Help != NULL)
							ShowWindow(Toolbar_Help, SW_SHOW);
					else
						MessageBox(hwnd, "Returned NULL", "Warning!",	
							MB_OK | MB_ICONINFORMATION);
			}
			break;
		}
		break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return ToolDlgProc(hwnd,Msg,wParam,lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor       = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_CURSOR1));
    wc.hbrBackground = CreateSolidBrush(RGB(10,200,10));
	wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
    wc.lpszClassName = ClassName;
	wc.hIconSm       = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON2),IMAGE_ICON,16,16,0);
    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        ClassName,
        "Arne Andersson Trees",
		WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 750, 550,
        NULL, NULL, hInstance, NULL);
    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }
	ShowWindow(hwnd, SW_SHOWMAXIMIZED);
    UpdateWindow(hwnd);
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}